<?php
/**
* This file belongs to the core webappkit package (kit)
* @link http://webappkit.net
* @package webappkit
* @author J.Ducastel <jeremie@ducastel.name>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

/**
 * Generic tool builder for Kits
 */
class wakTool {
	
	/**
	 * Kit's tool factory
	 * has to be implemented by children classes
	 * @static
	 * @param string $kit parent kit id
	 * @param string $name tool's unique name within kit
	 * @return object
	 */
	function & factory($kit,$name) {
		return new wakTool($kit,$name);
	}
/*--------------------------------------------------------------------
CONSTRUCTOR
--------------------------------------------------------------------*/
	/**
	* php4 constructor
	* @access public
	*/
	function wakTool(&$kit,$name) {
		$this->__construct($kit,$name);
	}/**/
	
	/**
	* "real" constructor.
	* will load conf
	* @access public
	* @param webappkit $kit parent kit's reference
	* @param string $name storage name within kit
	*/
	function __construct($kit,$name) {
		$this->kit=$kit;
		$this->name=$name;
		// loading config
		$this->_loadCfg();
		// doing some more initialization
		$this->_init();
	}/**/
/*--------------------------------------------------------------------
VARS / MEMBERS
--------------------------------------------------------------------*/
	/**
	* @var string parent kit id
	*/
	var $kit;
	
	/**
	* @var string self unique name within kit
	*/
	var $name;
	
	/**
	 *@var array configuration data
	 */
	var $cfg=array();
	
	/**
	* loads config ini file ( {name}.storage.ini )
	* @access protected
	* @return bool
	*/
	function _loadCfg() {
		// getting ini file
		$file=webappkit::getPath($this->kit).$this->name.'.tool.ini'; // echo $file;
		if (!file_exists($file) or !is_file($file)) {
			trigger_error("no config file for tool {$this->kit}->{$this->name} ($file)");
			return false;
		}
		// parsing, with sections
		if (!$cfg=parse_ini_file($file,true)) {
			trigger_error("failed to parse $file");
			return false;
		}
		$this->cfg=&$cfg;
		return true;
	}
	
	/**
	 *
	 */
	function _init() {
		return true;
	}
}
?>